package com.satis.viewmodel.sample

import android.app.Application
import android.content.Intent
import android.os.Bundle
import android.os.Handler
import android.widget.Toast
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModelProvider
import com.satis.viewmodel.annotation.Observe
import com.satis.viewmodel.apt.ObserveStore
import com.satis.viewmodel.core.BaseActivity
import com.satis.viewmodel.core.BaseViewModel
import com.satis.viewmodel.core.SatisViewModel

open class MainActivity : BaseActivity<MyViewModel>(){
    override fun onCreate(savedInstanceState: Bundle?) {
        SatisViewModel.addObserverStore(ObserveStore())
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
//        if (this::class.java.simpleName == "MainActivity"){
//            startActivity(Intent(this,MainActivity2::class.java))
//        }
        SatisViewModel.observe(this)
    }

    @Observe(tag = "test")
    fun onTest(s:String){
        Toast.makeText(this,s, Toast.LENGTH_SHORT).show()
    }

}

class  MyViewModel : BaseViewModel{
    constructor(application: Application):super(application){
        Handler().postDelayed({
                              setValue("test","测试 MainActivity")
        },1000
        )

        Handler().postDelayed({
            setValue("test1","测试 MainActivity2")
        },5000
        )
    }
    val liverData = MutableLiveData<String>()
}
